package com.lbb.simple.demo.controller

import com.lbb.http.GsonUtil
import com.lbb.http.HttpUtil
import com.lbb.http.call.CallBack
import com.lbb.mvp.presenter.BasePresenter
import com.lbb.mvp.view.BaseView
import com.lbb.simple.demo.bean.Banner
import com.lbb.simple.demo.http.Api

class BannerController {
    class BannerPresenter(view: BannerView?) : BasePresenter<BannerView>(view) {
        fun getBanner(type: Int) {
            view?.showLoadingBanner(type)
            HttpUtil.get(Api.banner, mapOf("type" to type.toString()), object : CallBack<String> {
                override fun complete() {

                }

                override fun success(string: String) {
                    val list = GsonUtil.toList(string,Banner::class.java)
                    view?.setBanner(type, list)
                }

                override fun error(string: String) {
                    view?.showErrorBanner(type)
                }

            })
        }

        override fun onCreate() {
            super.onCreate()
            getBanner(1)
        }
    }


    interface BannerView : BaseView {
        fun showLoadingBanner(type: Int)
        fun showErrorBanner(type: Int)
        fun setBanner(type: Int, banner: List<Banner>?)
    }
}